#include "stdafx.h"
#include "BookFile.h"


CBookFile::CBookFile()
{
}


CBookFile::~CBookFile()
{
}

uint CBookFile::WriteBook( char * filename, T_NODE * book, uint size )
{
    std::ofstream outfile;
    outfile.open(filename, ios::binary | ios::out);
    outfile.write((char*)(&size), sizeof(uint) );
    outfile.write((char*)  book, sizeof(T_NODE)*size ); // sizeof can take a type
    outfile.close();
    return 0;
};

uint CBookFile::ReadBook ( char * filename, T_NODE * book )
{
    cout << "Read Book..."<<endl;
    uint s=0;
    ifstream infile; 
    infile.open(filename, ios::binary | ios::in);
    infile.read((char*)&s, sizeof(uint)); 
    cout << "Nodes: "<<s <<endl;
    infile.read((char*) book, sizeof(T_NODE)*s); 
    return s; 
};